# -*- coding: utf-8 -*-#
#-------------------------------------------------------------------------------
# 建立者:        潘炎珍  
# Name:         demo04
# Description:
# Author:       98745
# Date:         2019/3/3
#-------------------------------------------------------------------------------

class N(Exception):
    pass
class Z(Exception):
    pass
class S:
    def add(self,x,y):
        if x<0 or y<0:
            raise N
        return x+y
    def sub(self,x,y):
        if x-y<0:
            raise x-y
        return x-y
    def mul(self,x,y):
        if x==0 or y==0:
            raise  x*y
        return x*y
    def div(self,x,y):
        return x/y

while True:
    try:
        c=S()
        e=input('请输入要计算的表达式，例如，add(1,2):')
        if e=='exit':
            break
        re=eval('c.'+e)
        print('计算结果：{:.2f}'.format(re))
    except N:
        print('***负数异常***')
    except Z:
        print('***操作数为0异常***')
    except ZeroDivisionError:
        print('***分母不为0异常***')
    except:
        print('***其他异常***')
